﻿using MT.Common.Helper;
using Microsoft.EntityFrameworkCore;

namespace MT.Models.Entity
{
    public partial class AppDbContext : DbContext
    {
        public AppDbContext()
        {
        }

        public AppDbContext(DbContextOptions<AppDbContext> options)
            : base(options)
        {
        }
     
       
      
       
        
        public virtual DbSet<User> User { get; set; }
        public virtual DbSet<UserBusinessRole> UserBusinessRole { get; set; }
        public virtual DbSet<UserInstitution> UserInstitution { get; set; }
        public virtual DbSet<UserLoginLog> UserLoginLog { get; set; }
        public virtual DbSet<UserOperateLog> UserOperateLog { get; set; }
        public virtual DbSet<UserRole> UserRole { get; set; }

        // Unable to generate entity type for table 'dbo.File'. Please see the warning messages.
        // Unable to generate entity type for table 'dbo.OnlineGoods'. Please see the warning messages.
        // Unable to generate entity type for table 'dbo.StoreSalesStrategyByDiscountRecord'. Please see the warning messages.

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (!optionsBuilder.IsConfigured)
            {
                optionsBuilder.UseSqlServer(ConfigHelper.GetSection("ConnectionStrings", "MedicalBeautyDatabase"));
            }
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.HasAnnotation("ProductVersion", "2.2.4-servicing-10062");
       
            modelBuilder.Entity<UserLoginLog>(entity =>
            {
                entity.Property(e => e.City).HasMaxLength(20);

                entity.Property(e => e.ClientTypeDic)
                    .IsRequired()
                    .HasMaxLength(50)
                    .IsUnicode(false)
                    .HasDefaultValueSql("((0))");

                entity.Property(e => e.Conent).HasMaxLength(200);

                entity.Property(e => e.CreateTime)
                    .HasColumnType("datetime")
                    .HasDefaultValueSql("(getdate())");

                entity.Property(e => e.District).HasMaxLength(20);

                entity.Property(e => e.Ip)
                    .HasColumnName("IP")
                    .HasMaxLength(50)
                    .IsUnicode(false);

                entity.Property(e => e.Nation).HasMaxLength(20);

                entity.Property(e => e.Province).HasMaxLength(20);
            });

            modelBuilder.Entity<UserOperateLog>(entity =>
            {
                entity.Property(e => e.ClientTypeDic)
                    .IsRequired()
                    .HasMaxLength(50)
                    .IsUnicode(false)
                    .HasDefaultValueSql("((0))");

                entity.Property(e => e.CreateTime)
                    .HasColumnType("datetime")
                    .HasDefaultValueSql("(getdate())");

                entity.Property(e => e.Ip)
                    .IsRequired()
                    .HasColumnName("IP")
                    .HasMaxLength(50)
                    .IsUnicode(false);

                entity.Property(e => e.OperateContent).HasMaxLength(100);

                entity.Property(e => e.OperateIds)
                    .IsRequired()
                    .HasMaxLength(50)
                    .IsUnicode(false);
            });

            modelBuilder.Entity<UserRole>(entity =>
            {
                entity.Property(e => e.AuthRoleTypeDic)
                    .IsRequired()
                    .HasMaxLength(50)
                    .IsUnicode(false)
                    .HasDefaultValueSql("((0))");

                entity.Property(e => e.CreateTime)
                    .HasColumnType("datetime")
                    .HasDefaultValueSql("(getdate())");

                entity.Property(e => e.InstitutionId).HasDefaultValueSql("((0))");
            });
        }
    }
}
